//
//  BiBaseIndexViewController.m
//  TrunkIndustryManageSystem
//
//  Created by WT_lyy on 15/4/25.
//  Copyright (c) 2015年 李璐西. All rights reserved.
//

#import "BiBaseIndexViewController.h"

@interface BiBaseIndexViewController ()<UITableViewDataSource,UITableViewDelegate>{
    
    UITableView * _tableView;
    
    NSMutableArray * _titleArr;
    
    NSMutableArray * _imageArr;
    
    UILabel * latb;
    
    UIButton * _leftBtn;
}

@end

@implementation BiBaseIndexViewController
- (id)init
{
    self = [super init];
    if (self)
    {
        _imageArr = [[NSMutableArray alloc] init];
        
        _titleArr = [[NSMutableArray alloc] init];
    }
    return self;
    
}


- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self setNavBackBtn];
    
    [self setNavBarWithHidden:YES];
    [self addTestView];
    self.view.backgroundColor = UIColorFromRGB(0xfafbfc);
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, [self viewTop], MAIN_SCREEN_WIDTH, MAIN_SCREEN_HEIGHT-[self viewTop])];
    
    [self.view addSubview:_tableView];
    
    _tableView.delegate = self;
    
    _tableView.dataSource = self;
    
    UIImageView * imv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, MAIN_SCREEN_WIDTH, 150)];
    
    latb = GET_LABEL(CGRectMake(0, 66, 320, 16), 17, NO, [UIColor whiteColor], NSTextAlignmentCenter);
    [imv addSubview:latb];
    imv.image = LOAD_IMAGE_WITH_CACHE(@"common/icon_background");
    
    _tableView.tableHeaderView = imv;
    
    _tableView.rowHeight = 67;
    
    _tableView.scrollEnabled = NO;
    _tableView.backgroundColor = UIColorFromRGB(0xfafbfc);
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    
    _leftBtn = GET_BUTTON(CGRectMake(0, 20, 44, 44), 12, NO, [UIColor whiteColor]);
    _leftBtn.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_leftBtn];
     [_leftBtn setImage:LOAD_IMAGE_WITH_CACHE(@"common/icon_main_back.png") forState:UIControlStateNormal];
    [_leftBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
}

- (void)backClick{

    [self.navigationController popViewControllerAnimated:YES];
}

- (void)refreshTable:(NSArray *)titleArr imageArr:(NSArray *)imageArr title:(NSString *)title{

    [_titleArr removeAllObjects];
    
    [_titleArr addObjectsFromArray:titleArr];
    
    [_imageArr removeAllObjects];
    
    [_imageArr addObjectsFromArray:imageArr];
    
  //  [self setNavBarTitle:title];
    
    [_tableView reloadData];
    
    latb.text = title;
}


#pragma -mark UitabeViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    

}

#pragma -mark UitabeViewDatasource

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    

    NSInteger count =  _imageArr.count > _titleArr.count ? _titleArr.count:_imageArr.count;
    
    return count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
   static NSString * myIndentifier = @"IndexListCell";
    
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:myIndentifier];
    
    if (!cell) {
        
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myIndentifier];
        
        UIView * view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 6, 60, 60)];
        view1.backgroundColor = UIColorFromRGB(0xeef4fd);
        [cell addSubview:view1];
        
        UIView * view2 = [[UIView alloc] initWithFrame:CGRectMake(60, 6, MAIN_SCREEN_WIDTH-60, 60)];
        view2.backgroundColor = UIColorFromRGB(0xfafbfc);
        [cell addSubview:view2];
        
        UIImageView * imv = [[UIImageView alloc] initWithFrame:CGRectMake(18, 24, 25, 25)];
        
        [cell addSubview:imv];
        
        imv.tag = 1;
        
        UILabel * lab = GET_LABEL(CGRectMake(60, 25, 200, 16), 15, NO, [UIColor darkGrayColor], NSTextAlignmentCenter);
        
        [cell addSubview:lab];
        
        lab.tag = 2;
    }
    
    UIImageView * imv = (UIImageView *)[cell viewWithTag:1];
    UILabel * lab = (UILabel *)[cell viewWithTag:2];
    
    imv.image = LOAD_IMAGE_WITH_CACHE(_imageArr[indexPath.row]);
    lab.text = _titleArr[indexPath.row];
    
    cell.backgroundColor = UIColorFromRGB(0xe6e6e6);
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

@end
